#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :test.py
# @Time      :2023/10/26 
# @Author    :CL
# @email     :1037654919@qq.com
import re
from lvmama import Lvmama
from scenery import get_scenery
from utils import mongo_manager

if __name__ == '__main__':
    lvmama = Lvmama()
    lvmama_mudidi = mongo_manager('lvmama_mudidi', db='lvyou')
    # lvmama_mudidi.updateMany({'status':'success'},{'status':None})
    seeds = lvmama_mudidi.findAll({'base_id': None})
    for seed in seeds:
        print(seed['_id'])
        href = seed['_id']
        match = re.search(r'\d+', href)
        if match:
            dest_id = match.group()
            print("dest_id值为: " + dest_id)
            seed['dest_id'] = dest_id

        else:
            print('未找到dest_id')
            continue
        baseurl = seed['href']

        # 使用正则表达式匹配 "base_id" 的值
        try:
            response = get_scenery(baseurl)
            match = re.search(r'base_id\s*:\s*"(\d+)"', response)
            if match:
                base_id = match.group(1)
                print("base_id值为: " + base_id)
                seed['base_id'] = base_id
            else:
                print("未找到base_id值")
                continue
        except:
            continue
        lvmama_mudidi.updateOne({"_id": seed["_id"]}, seed)
    lvmama_mudidi.close()